<?php
	include '../include/functions.php';
//set session save path
session_save_path($session_path);
// Initialize a session. 
session_start();
$count++;
$start = time();
$sessionId = session_id();

?>
<!DOCTYPE html PUBLIC "-//W3C//Dtd html 4.01 Transitional//EN"
"http://www.w3.org/tr/html4/loose.dtd">
<html>
  <head>
    <title>JoshHughes.com NHL Hockey Pool</title>
	<link rel="shortcut icon" href="http://hockey.joshhughes.com/NHL/images/nhlFavicon.gif" />
	<link rel="stylesheet" href="http://hockey.joshhughes.com/css/NHL.css" type="text/css">
    <script src="http://hockey.joshhughes.com/scripts/prototype.js" type="text/javascript"></script>
	<script src="http://hockey.joshhughes.com/scripts/scriptaculous.js" type="text/javascript"></script>
	<script type="text/javascript">
	// Dynamic Iframe loader
	function loadmonkeyframe(theURL)
	{
		document.getElementById("monkeyframe").src=theURL;
	}
	function loadpollframe(theURL)
	{
		document.getElementById("pollframe").src=theURL;
	}
	
	// resizes Iframe according to content
	function resizeMe(obj){ 
	docHeight = obj.document.body.scrollHeight
	 obj.style.height = docHeight + 5 + 'px'
	 } 
	</script>
  </head>
<body>
<div id="pagewidth" >
	<div id="header" >
	
		<?PHP include_once("layout/header.html"); ?>
		
	</div>
			<div id="wrapper" class="clearfix" > 
			<div id="maincol" >

			<!-- InstanceBeginEditable name="Contents" -->					
			<table cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">
				<tr>
					<td align="center"><h2>Weekly Winners</h2></td>
				</tr>
				<tr>
					<td class="redbg">
						<?php
						dbConnect();
						?>
						
						<table bgcolor="#FFFFFF" border="0" callpadding="5" cellspacing="0" align="center">
							<tr bgcolor="#FFFFFF">
								<th width="50" align="left">Week</th>
								<th width="250" align="left">Winner(s)</th>
								<th width="100" align="left">Week Score</th>
								<th width="100" align="left">Magic Guess</th>
								<th width="60" align="left">Magic #</th>
							</tr>
							<tr bgcolor="#FFFFFF">
								<td colspan="5"><hr align="left" size="2" class="redbg" /></td>
							</tr>
							<?
							//Get Data From Users Who Picked
							$query="SELECT * FROM NHLWeeklyWinner ORDER BY Week";
							$result = mysql_query($query) or die("Cannot query the database.<br/>");
							$row = 0;
							do{
								if ($myrow["UserID"] != NULL)
								{
									$users = explode (",",$myrow["UserID"]);
									if (in_array($userID, $users))
										echo "<tr bgcolor=\"#ffff33\">";
									else
										echo "<tr bgcolor=\"".getRowColor($row)."\">";
									echo "	<td align=\"center\"><b><a href=\"breakdown.php?Weeknum=".$myrow["Week"]."\" class=\"permLink\" style=\"color: #0000ff; text-decoration: none;\">".$myrow["Week"]."</a></b></td>
										<td>";
									$nextstring = "";
									foreach ($users as $value)
										$nextstring .= makeUserLink($value)." & ";
									
									$nextstring = substr($nextstring, 0, strlen($nextstring)-3);	
									echo "$nextstring</td>
										<td align=\"center\">".$myrow["Score"]." / ".$myrow["NumGames"]."</td>
										<td align=\"center\">";
									if($myrow["MagicGuess"] == 0)
										echo "-";
									else
										echo $myrow["MagicGuess"];
									echo "</td>
										<td align=\"center\">".$myrow["MagicNum"]."</td>";
									$row++;
								}
							}while($myrow = mysql_fetch_array($result));
							
							?>
						</table>
					</td>
				</tr>
			</table><br/>
			<p>
				<b>Magic Guess</b> represents the "Magic Number" guess that user made for the week to determine them the weekly winner.<br/>
				<b>Magic Number</b> is the <i>combined</i> final score of the last game of the week.<br/><br/>
				Weeks in which you have won will be highlighted in yellow (if you are logged in of course).
			</p>
			
			</div> <!-- Close maincol div   -->
		
		<div id="leftcol" >		
			<?PHP include_once("layout/left_column.php"); ?>		
		</div>
		
			
	</div> <!-- Close wrapper div   -->

	<div id="footer" >	
		<?PHP include_once("layout/footer.html"); ?>	
	</div>

		
</div>
</body>
</html>